#pragma once
#include <OgreVector3.h>
#include <OgreQuaternion.h>
#include <string>
Ogre::Vector3 fixCoordSystem(Ogre::Vector3 v);
Ogre::Vector3 fixCoordSystem2(Ogre::Vector3 v);
Ogre::Quaternion fixCoordSystemQuat(Ogre::Quaternion v);

float frand();
float randfloat(float lower, float upper);
int randint(int lower, int upper);
void fixname(std::string &name);
void fixnamen(char *name, size_t len);

void gLog(char *str, ...);


const int stripsize2 = 16*18 + 7*2 + 8*2;
const int stripsize = 8*18 + 7*2;

int indexMapBuf(int x, int y);
template <class V>
void stripify(V *in, V *out)
{
    for (int row=0; row<8; row++) {
        V *thisrow = &in[indexMapBuf(0,row*2)];
        V *nextrow = &in[indexMapBuf(0,(row+1)*2)];

        if (row>0) *out++ = thisrow[0];
        for (int col=0; col<9; col++) {
            *out++ = thisrow[col];
            *out++ = nextrow[col];
        }
        if (row<7) *out++ = nextrow[8];
    }
}

// high res version, size = 16*18 + 7*2 + 8*2
template <class V>
void stripify2(V *in, V *out)
{
    for (int row=0; row<8; row++) { 
        V *thisrow = &in[indexMapBuf(0,row*2)];
        V *nextrow = &in[indexMapBuf(0,row*2+1)];
        V *overrow = &in[indexMapBuf(0,(row+1)*2)];

        if (row>0) *out++ = thisrow[0];// jump end
        for (int col=0; col<8; col++) {
            *out++ = thisrow[col];
            *out++ = nextrow[col];
        }
        *out++ = thisrow[8];
        *out++ = overrow[8];
        *out++ = overrow[8];// jump start
        *out++ = thisrow[0];// jump end
        *out++ = thisrow[0];
        for (int col=0; col<8; col++) {
            *out++ = overrow[col];
            *out++ = nextrow[col];
        }
        if (row<8) *out++ = overrow[8];
        if (row<7) *out++ = overrow[8];// jump start
    }
}

void BuildDetailIndices(unsigned short *pIndices, unsigned int nGrideSize);
void BuildRoughIndices(unsigned short *pIndices, unsigned int nGrideSize);